package com.cyber4aiagent.config;

import dev.langchain4j.memory.chat.ChatMemoryProvider;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.cyber4aiagent.store.MongoChatMemoryStore;

/**
 * @author Cyber
 * @date 2025/05/09 10:45
 * @description 隔离聊天记忆功能的 AIService 配置
 */
@Configuration
public class SeparateChatAssistantConfig {

    @Autowired
    private MongoChatMemoryStore mongoChatMemoryStore;

    @Bean
    public ChatMemoryProvider chatMemoryProvider() {
        return memoryId -> MessageWindowChatMemory.builder()
                .id(memoryId)
                .maxMessages(10)
                // chatMemoryStore: 隔离聊天记忆功能的存储
                // 两种存储：1、SingleSlotChatMemoryStore --> private List<ChatMessage> messages = new ArrayList();
                //          2、InMemoryChatMemoryStore --> private Map<Integer, List<ChatMessage>> messages = new HashMap();
//                .chatMemoryStore(new InMemoryChatMemoryStore())
                // 使用自定义的 MongoChatMemoryStore 实现聊天记忆的持久化
                .chatMemoryStore(mongoChatMemoryStore)
                .build();
    }
}
